package com.lu.article.listener;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.lu.article.service.ApArticleConfigService;
import com.lu.common.constants.WmNewsShelfConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class ApArticleWmNewsListener {

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsShelfConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void listener(String msg) {
        if (StringUtils.isNotBlank(msg)) {
            Map map = JSON.parseObject(msg, Map.class);
            //修改
            apArticleConfigService.updateByMap(map);
            log.info("app端文章{}已修改状态,enable = {}", map.get("articleId"), map.get("enable"));
        }
    }
}
